#!/bin/bash

cat parameters.dat | grep xsize > temp
sed -i "s/\txsize//g" temp
xsize=$(sed "s/\#//g" temp)
echo "...xsize=$xsize"
cat parameters.dat | grep ysize > temp
sed -i "s/\tysize//g" temp
ysize=$(sed "s/\#//g" temp)
echo "...ysize=$ysize"
cat parameters.dat | grep steps > temp
sed -i "s/\tsteps//g" temp
steps=$(sed "s/\#//g" temp)
echo "...steps=$steps"
cat parameters.dat | grep tconv > temp
sed -i "s/\ttconv//g" temp
tconv=$(sed "s/\#//g" temp)
echo "...steps=$tconv"



gnuplot << EOF
        set terminal png
	set output "data/average_transport_length.png"
	set ylabel "average transport length on grid"
	set xlabel "timesteps"	

        plot "./dynamics.dat" u 1:2 w l
EOF

gnuplot << EOF
	set terminal png
	set output "data/average_hight.png"
	set ylabel "average hight on cell"
	set xlabel "timesteps"	

        plot "./dynamics.dat" u 1:3 w l
EOF

gnuplot << EOF
	set terminal png
	set output "data/average_eroded_hight.png"
	set ylabel "average eroded hight per cell per iteration"
	set xlabel "timesteps"	

        plot "./dynamics.dat" u 1:4 w l
EOF

gnuplot << EOF
	set terminal png
	set output "data/average_outflow.png"
	set ylabel "outflux from grid per boundary cell"
	set xlabel "timesteps"

	plot "./dynamics.dat" u 1:5 w l
EOF

gnuplot << EOF
        set terminal png
	set output "data/average_volume_flux.png"
	set ylabel "average volume flux on grid"
	set xlabel "timesteps"	

        plot "./dynamics.dat" u 1:6 w l
EOF

gnuplot << EOF
	set terminal png
	set output "data/fourier_comps.png"
	set xrange [0:$xsize]
   	set yrange [0:$ysize]

   		plot "./fouriercomps.dat" binary array=($xsize,$ysize) format="%float" with image
EOF

gnuplot << EOF
	set terminal png
	set output "data/sliced_average_flux.png"
	set xrange [0:$steps]
	set yrange [0:$ysize]
#  	set size ratio -1

		plot "./sliced_average_flux.dat" binary array=($steps+1,$ysize) with image
EOF

gnuplot << EOF
	set terminal png
	set output "data/sliced_average_hight.png"
	set xrange [0:$steps]
	set yrange [0:$ysize]
#  	set size ratio -1

		plot "./sliced_average_hight.dat" binary array=($steps+1,$ysize) with image
EOF

gnuplot << EOF
	set terminal png
	set output "data/sliced_erosion_hight.png"
	set xrange [0:$steps]
	set yrange [0:$ysize]
#  	set size ratio -1

		plot "./sliced_erosion_hight.dat" binary array=($steps+1,$ysize) with image
EOF

gnuplot << EOF
	set terminal png
	set output "data/sliced_transport_length.png"
	set xrange [0:$steps]
	set yrange [0:$ysize]
#  	set size ratio -1

		plot "./sliced_transport_length.dat" binary array=($steps+1,$ysize) with image
EOF

gnuplot << EOF
        set terminal png
        set output "data/sliced_covered_cells.png"
        set xrange [0:$steps]
        set yrange [0:$ysize]
#       set size ratio -1

                plot "./sliced_covered_cells.dat" binary array=($steps+1,$ysize) with image
EOF


gnuplot << EOF
	set terminal png
	set output "data/mean_covered_cells.png"

		plot "./mean_covered_cells.dat" u 1:2 w l
EOF



gnuplot << EOF
	set terminal png
	set output "data/2d_hight_envelope.png"
	set xrange [0:$xsize]
	set yrange [0:$ysize]
#  	set size ratio -1

		plot "./2d_envelope.dat" binary array=($xsize,$ysize) with image
EOF


